package com.ttwm.dao;

import com.ttwm.pojo.Comment;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Repository
public interface CommentDao {
    @Insert("insert into t_comment(foodId,userId,comments,data) values (#{foodId},#{userId},#{comments},#{data})")
    int addComment(Comment comment);

    @Select("select * from t_comment where foodId=#{foodId} order by commentId desc")
    @Results({
            @Result(id = true,property = "commentId",column = "commentId"),
            @Result(property = "oneUser",column = "userId",
                    many = @Many(select = "com.ttwm.dao.UserDao.oneUser"))
    })
    List<Comment> commentList(Comment comment);

    @Select("select * from t_comment where commentId=#{commentId}")
    Comment oneComment(Comment comment);

    @Delete("delete from t_comment where commentId=#{commentId}")
    int deleteComment(Comment comment);

    @Update("update t_comment set comments=#{comments},data=#{data} where commentId=#{commentId}")
    int updateComment(Comment comment);

    @Delete("delete from t_comment where userId=#{userId}")
    int deleteCommentAll(Comment comment);

}
